package weaver.interfaces.autolink.action;

import com.weaver.general.BaseBean;
import com.weaver.general.Util;
import weaver.conn.RecordSet;
import weaver.hrm.resource.ResourceComInfo;
import weaver.interfaces.autolink.utils.AutoLinkUtil;
import weaver.interfaces.workflow.action.Action;
import weaver.soa.workflow.request.RequestInfo;

import java.util.HashMap;
import java.util.Map;

/**
 * @Title: ecology-9-demo
 * @Company: 泛微软件
 * @author: weaver.Dusongsong
 * @version: 1.0
 * @CreateDate: 2020-10-23
 * @Description: 1、绩效等级不等于B ，流程结束触发子流程：绩效面谈流程，到直接上级节点
 * @ModifyLog:
 **/
public class WeaOKRjxhzqrAction extends BaseBean implements Action {
    @Override
    public String execute(RequestInfo requestInfo) {
        RecordSet rs = new RecordSet();
        String requestid = requestInfo.getRequestid();
        String tablename = requestInfo.getRequestManager().getBillTableName();
        writeLog(">>>>>WeaOKRjxhzqrAction>>>>>requestid=" + requestid);
        try {
            AutoLinkUtil autoLinkUtil = new AutoLinkUtil();
            String sql = "select * from " + tablename + " where requestid=?";
            rs.executeQuery(sql, requestid);
            rs.next();
            String mainid = Util.null2String(rs.getString("id"));
            String dh = Util.null2String(rs.getString("dh"));
            String sfsndjx = Util.null2String(rs.getString("sfsndjx"));
            String tjrq = Util.null2String(rs.getString("tjrq"));
            rs.executeQuery("select * from " + tablename + "_dt1 where mainid=? and jxpgdj !=2 ", mainid);
            String workflowId = "77";
            ResourceComInfo resourceComInfo = new ResourceComInfo();
            int counts = rs.getCounts();
            int count = 0;
            while (rs.next()) {
                Map<String, Object> requestMainMap = new HashMap<>();
                requestMainMap.put("dh", dh);
                String ygxm = Util.null2String(rs.getString("ygxm"));
                requestMainMap.put("gh", Util.null2String(rs.getString("gh")));
                requestMainMap.put("bkhxm", ygxm);
                requestMainMap.put("dw", Util.null2String(rs.getString("dw")));
                requestMainMap.put("bm", Util.null2String(rs.getString("bm")));
                requestMainMap.put("gw", Util.null2String(rs.getString("zw")));
                requestMainMap.put("khzqn", Util.null2String(rs.getString("nd")));
                requestMainMap.put("jxpgdj", Util.null2String(rs.getString("jxpgdj")));
                requestMainMap.put("khzqy", Util.null2String(rs.getString("pjqj")));
                requestMainMap.put("mtr", Util.null2String(rs.getString("zjsj")));
                requestMainMap.put("sfsndjxkh", sfsndjx);
                String requestName = "绩效面谈流程-" + tjrq + "-" + resourceComInfo.getLastname(ygxm);
                String newRequestid = autoLinkUtil.WorkflowCreateByRequestMap(ygxm, workflowId, requestName, "1", requestMainMap);
                if (Util.getIntValue(newRequestid) > 0) {
                    count++;
                }
            }
            if (counts == count) {
                return Action.SUCCESS;
            } else {
                requestInfo.getRequestManager().setMessageid("111111");
                requestInfo.getRequestManager().setMessagecontent("触发绩效面谈流程未完成");
                return Action.FAILURE_AND_CONTINUE;
            }

        } catch (Exception e) {
            e.printStackTrace();
            writeLog("异常参考:" + e);
            requestInfo.getRequestManager().setMessageid("111111");
            requestInfo.getRequestManager().setMessagecontent("Action接口异常");
            return Action.FAILURE_AND_CONTINUE;
        }
    }
}

